package com.me.jingdongshop.ui.holder;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.me.common.ui.BaseAdapterLV;
import com.me.common.ui.BaseHolderLV;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.HomeRecommendedBrand;
import com.me.jingdongshop.ui.adapter.GridViewAdapter;
import com.me.jingdongshop.ui.view.MyGridView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;


/**
 * Created by Tm on 2017/5/4.
 */

public class DisHolderLv extends BaseHolderLV<HomeRecommendedBrand.BrandBean> {

    private TextView disTitle;
    private MyGridView isGl;


    public DisHolderLv(Context context, ViewGroup parent, BaseAdapterLV<HomeRecommendedBrand.BrandBean> adapter,
                       int position, HomeRecommendedBrand.BrandBean bean) {
        super(context, parent, adapter, position, bean);

    }


    @Override
    public View onCreateView(Context context, ViewGroup parent) {
        final View view = LayoutInflater.from(context).inflate(R.layout.dis_lv_items, parent, false);

        disTitle = (TextView) view.findViewById(R.id.dis_title);
        isGl = (MyGridView) view.findViewById(R.id.is_gl);

        return view;
    }

    @Override
    protected void onRefreshView(final HomeRecommendedBrand.BrandBean bean, int position) {
        //titlet
        disTitle.setText(adapter.listData.get(position).getKey());

        GridViewAdapter girdAdapter = new GridViewAdapter(adapter.listData.get(position).getValue(), context);

        isGl.setAdapter(girdAdapter);


        disTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bean.vis) {
                    isGl.setVisibility(View.GONE);
                    bean.vis = false;
                } else {
                    isGl.setVisibility(View.VISIBLE);
                    bean.vis = true;
                }
                adapter.notifyDataSetChanged();
            }
        });


    }


}
